/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entregapersistencia;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author dianacha
 */
@Entity
@Table(name = "terminal")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Terminal.findAll", query = "SELECT t FROM Terminal t"),
    @NamedQuery(name = "Terminal.findByNumeroTerminal", query = "SELECT t FROM Terminal t WHERE t.terminalPK.numeroTerminal = :numeroTerminal"),
    @NamedQuery(name = "Terminal.findByIdUsuario", query = "SELECT t FROM Terminal t WHERE t.terminalPK.idUsuario = :idUsuario"),
    @NamedQuery(name = "Terminal.findByActivo", query = "SELECT t FROM Terminal t WHERE t.activo = :activo")})
public class Terminal implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TerminalPK terminalPK;
    @Basic(optional = false)
    @Column(name = "activo")
    private boolean activo;
    @JoinColumn(name = "id_usuario", referencedColumnName = "identificacion", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Usuario usuario;
    @JoinColumn(name = "sucursal", referencedColumnName = "id")
    @ManyToOne
    private Sucursal sucursal;

    public Terminal() {
    }

    public Terminal(TerminalPK terminalPK) {
        this.terminalPK = terminalPK;
    }

    public Terminal(TerminalPK terminalPK, boolean activo) {
        this.terminalPK = terminalPK;
        this.activo = activo;
    }

    public Terminal(String numeroTerminal, String idUsuario) {
        this.terminalPK = new TerminalPK(numeroTerminal, idUsuario);
    }

    public TerminalPK getTerminalPK() {
        return terminalPK;
    }

    public void setTerminalPK(TerminalPK terminalPK) {
        this.terminalPK = terminalPK;
    }

    public boolean getActivo() {
        return activo;
    }

    public void setActivo(boolean activo) {
        this.activo = activo;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Sucursal getSucursal() {
        return sucursal;
    }

    public void setSucursal(Sucursal sucursal) {
        this.sucursal = sucursal;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (terminalPK != null ? terminalPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Terminal)) {
            return false;
        }
        Terminal other = (Terminal) object;
        if ((this.terminalPK == null && other.terminalPK != null) || (this.terminalPK != null && !this.terminalPK.equals(other.terminalPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entregapersistencia.Terminal[ terminalPK=" + terminalPK + " ]";
    }
    
}
